package com.yc.edu.dao;

import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.yc.edu.pojo.Message;
import com.yc.edu.pojo.PostComments;
import org.apache.ibatis.annotations.Insert;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Select;

import java.util.List;

@Mapper
public interface MessageDAO extends BaseMapper<Message> {
    @Select("SELECT * FROM message WHERE (username = #{username} AND to_username = #{toUsername}) " +
            "OR (username = #{toUsername} AND to_username = #{username}) ORDER BY create_time ASC")
    List<Message> getMessagesByUsernames(String username, String toUsername);

    @Insert("INSERT INTO message (username, message, to_username, create_time) " +
            "VALUES (#{username}, #{message}, #{toUsername}, #{createTime})")
    void saveMessage(Message message);
}
